package com.matrixlearning.controller;

import com.matrixlearning.pojo.User;
import com.matrixlearning.utils.GsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/learn")
public class LearnController {
    /**
     * Auther sun
     * DATE 2023/2/15 16:53
     * VERSION 1.0
     */

    @Autowired
    RedisTemplate redisTemplate;

    @PostMapping("/getLearnData")
    public String getLearnData(@RequestBody String token) {
        String userJson = (String) redisTemplate.opsForValue().get("user:" + token);
        User user = GsonUtils.fromJson(userJson, User.class);
        Map<String, Object> resMap = new HashMap<>();
        resMap.put("avatar", user.getAvatar());
        String resJson = GsonUtils.toJson(resMap);
        return resJson;
    }
}
